<template>
  <div class="">
    <u-modal
      v-model="visible"
      :title-style="{ color: 'red' }"
      border-radius="0"
      :showTitle="false"
      confirm-text="确认接单"
      confirm-color="#FF874FFF"
      :async-close="true"
      @confirm="onConfirmClick"
    >
      <view class="confirm-text"> 是否确认接单？ </view>
    </u-modal>
    <!-- toast -->
    <u-toast ref="uToast" />
  </div>
</template>
<script>
import { getOrderDetail, getOrderPrice, confirmOrder } from "@/api/qccx.js";
export default {
  data() {
    return {
      visible: false,
      form: {},
    };
  },
  methods: {
    show(record) {
      this.visible = true;
      this.form.id = record.id;
    },
    getDetail(id, callback) {
      getOrderDetail({ id: id }).then((res) => {
        const result = res.result;
        this.form.clientType = result.clientType;
        this.form.clientId = result.clientId;
        this.form.clientName = result.clientName;
        this.form.staffId = result.staffId;
        this.form.accountNumber = result.accountNumber;
        this.form.cityCode = result.cityCode;
        this.form.cityName = result.cityName;
        this.form.productType = result.productType;
        this.form.useDay = result.useDay;
        this.form.flightNumber = result.flightNumber;
        this.form.expectStartTime = result.expectStartTime;
        this.form.expectEndTime = result.expectEndTime;
        this.form.ruleEndTime = result.ruleEndTime;
        this.form.modelGroupId = result.modelGroupId;
        this.form.bookerId = result.bookerId;
        this.form.bookerName = result.bookerName;
        this.form.bookerPhone = result.bookerPhone;
        this.form.userInfoList = result.userInfoList;
        this.form.startAddressId = result.startAddressId;
        this.form.startAddress = result.startAddress;
        this.form.startAddressName = result.startAddressName;
        this.form.endAddressId = result.endAddressId;
        this.form.endAddress = result.endAddress;
        this.form.endAddressName = result.endAddressName;
        // 经纬度
        this.form.startAddressLatitude = result.startAddressLatitude;
        this.form.startAddressLongitude = result.startAddressLongitude;
        this.form.endAddressLatitude = result.endAddressLatitude;
        this.form.endAddressLongitude = result.endAddressLongitude;
        // 举牌相关
        this.form.liftBoard = result.liftBoard;
        this.form.boardContent = result.boardContent;
        // 中途停靠
        this.form.expectWaypointList = result.expectWaypointList;
        this.form.bookerSendMsg = result.bookerSendMsg;
        this.form.userSendMsg = result.userSendMsg;
        this.form.remark = result.remark;
        this.form.driverSex = result.driverSex;
        this.form.driverNeedList = result.driverNeedList;
        // 预估费用
        this.form.expectFeeInfo = result.expectFeeInfo;

        callback && callback();
      });
    },
    getDefaultPrice(callback) {
      let param = {
        clientType: this.form.clientType,
        cityCode: this.form.cityCode,
        productType: this.form.productType,
        modelGroupId: this.form.modelGroupId,
        clientId: this.form.clientId,
        startAddressName: this.form.startAddressName,
        endAddressName: this.form.endAddressName,
        useDay: this.form.useDay,
      };
      getOrderPrice(param).then((res) => {
        const result = res.result;
        // agreeType 价格规则 有值时，代表获取到了规则，计算到了初始费用
        if (result.agreeType) {
          this.form.agreeType = result.agreeType;
          this.form.agreeTypeName = result.agreeTypeName;
          this.form.initBasePrice = result.initBasePrice; //原基础费用
          this.form.initBaseAmount = result.initBaseAmount; //原基础总价
          this.form.discount = result.discount; //企业折扣
          this.form.discountAmount = result.discountAmount; //企业折扣总价
          this.form.baseAmount = result.baseAmount; //现基础费用
        }

        callback && callback();
      });
    },
    onConfirmClick() {
      this.getDetail(this.form.id, () => {
        this.getDefaultPrice(() => {
          if (this.form.agreeType) {
            confirmOrder(this.form).then((res) => {
              if (res.code == 200) {
                this.$refs.uToast.show({ title: "操作成功" });
                this.visible = false;
                this.$emit("success");
              }
            });
          } else {
            this.$toast("未获取到费用信息");
            this.visible = false;
          }
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.confirm-text {
  font-size: 32rpx;
  color: #1a1a1a;
  line-height: 48rpx;
  padding: 64rpx 48rpx;
  text-align: center;
}
</style>
